<template>
  <div class="">
    <div class="head">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="" prop="query">
          <el-input
            v-model="queryParams.query"
            placeholder="卡名称/发行方/交易单号/交易流水/用户姓名/手机号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="交易时间">
          <el-date-picker clearable
              v-model="date"
              type="daterange"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="changeTime"
              placeholder="选择交易时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单状态：" prop="">
          <el-select v-model="queryParams.status" placeholder="请选择" clearable style="width: 240px">
            <el-option v-for="(item,index) in statusLs" :key="index" :label="item.value" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
       <div style="margin-bottom: 14px">
          <export-excel-button
          title="发行购买订单"
          action="/fundsManager/equityCardBill/export"
          :params="ExportParams"
        />
       </div>

      <el-table v-loading="loading" :data="equityCardBillList" stripe border @selection-change="handleSelectionChange">
        <el-table-column type="index" label="序号" width="55" align="center" fixed/>
        <el-table-column label="卡编号" align="center" prop="cardNo" :show-overflow-tooltip="true"/>
        <el-table-column label="卡名称" align="center" prop="cardName" :show-overflow-tooltip="true"/>
        <el-table-column label="发行方名称" align="center" prop="name" :show-overflow-tooltip="true" width="120"/>
        <el-table-column label="交易单号" align="center" prop="relevancyNo" :show-overflow-tooltip="true"/>
        <el-table-column label="交易流水" align="center" prop="relevancySerialNo" :show-overflow-tooltip="true"/>
        <el-table-column label="交易时间" align="center" prop="transactionTime" :show-overflow-tooltip="true"/>
        <el-table-column label="交易类型" align="center"  :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <dict-tag :options="equityType" :value="scope.row.billType" />
          </template>
        </el-table-column>
        <el-table-column label="用户姓名" align="center" prop="customerName" :show-overflow-tooltip="true"/>
        <el-table-column label="联系方式" align="center" prop="customerPhone" :show-overflow-tooltip="true"/>
        <el-table-column label="交易金额" align="center" prop="orderMoney" :show-overflow-tooltip="true"/>
        <el-table-column label="积分抵扣" align="center" prop="integralUseAmount" :show-overflow-tooltip="true"/>
        <el-table-column label="优惠金额" align="center" prop="discountsMoney" :show-overflow-tooltip="true"/>
        <el-table-column label="实付金额" align="center" prop="payMoney" :show-overflow-tooltip="true"/>
        <el-table-column label="手续费" align="center" prop="transactionFee" :show-overflow-tooltip="true"/>
        <el-table-column label="铸造费" align="center" prop="castFee" :show-overflow-tooltip="true"/>
        <el-table-column label="订单状态" align="center" prop="status" :show-overflow-tooltip="true" width="120">
          <template slot-scope="scope">
            <dict-tag :options="statusLs" :value="scope.row.status" />
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    

    <Dialog ref="dialog" @refresh="getList"></Dialog>
  </div>
</template>

<script>
import { adminDict,listEquityCardBill, delEquityCardBill, exportEquityCardBill } from "@/api/equityCardBill";
import Dialog from "@/views/moneyManagement/equityCardBill/dialog";
import ExportExcelButton from "@/components/ExportExcelButton/index";
// import { splice } from 'mock/article';

export default {
  name: "EquityCardBill",
  // dicts: ['equity_card_bill_type'],
  components: {
    ExportExcelButton,
    Dialog
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 数字权益卡购卡账单查询表格数据
      equityCardBillList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        query: '',
        endDate: '',
        startDate: '',
        status:'',//订单状态（1待支付 2 已完成 3 已取消 ） 字典值 order_status
      },
      date: [],
      equityType: [],//交易类型字典
      statusLs:[],//订单状态字典order_status
    };
  },
  computed: {
    ExportParams() {
      const params = {
        ...this.queryParams,
      };
      return params;
    },
  },
  created(){
    this.getlinkagelist()
    var query = this.$route.query.name
    if(query){
      this.queryParams.query = query
    }
    this.getList();
  },
 
  methods: {
    getlinkagelist() {
      //获取字典
      const params = {
        dictType: "equity_card_bill_type,order_status",
      };
      adminDict(params).then((res) => {
        this.equityType = res.result[0].dictList;//交易类型
        this.statusLs = res.result[1].dictList;//订单状态
        this.statusLs.splice(3,1);
      });
    },
    /** 查询数字权益卡购卡账单查询列表 */
    getList() {
      this.loading = true;
      listEquityCardBill(this.queryParams).then(response => {
        this.equityCardBillList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        query: '',
        endDate: '',
        startDate: '',
        status:'',
      };
      this.date = []
    },
    changeTime(time){
      if(!time){
        this.date = []
        this.queryParams.startDate = ''
        this.queryParams.endDate = ''
      }else{
        this.queryParams.startDate = this.date[0]
        this.queryParams.endDate = this.date[1]
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.dialog.open();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.dialog.open(row.id);
    },
    /** 详情按钮操作 */
    handleView(row) {
      this.$refs.dialog.open(row.id, true);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除？').then(() => {
            this.loading = true;
            return delEquityCardBill(ids);
        }).then(() => {
            this.loading = false;
            this.getList();
            this.$modal.msgSuccess("删除成功");
        }).finally(() => {
            this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
        const queryParams = this.queryParams;
        this.$modal.confirm('是否确认导出所有数字权益卡购卡账单查询数据项？').then(() => {
            this.exportLoading = true;
            return exportEquityCardBill(queryParams);
        }).then(response => {
            this.$download.name(response.msg);
            this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
<style lang="scss" scoped>
.head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;
  }
  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px;
    margin-top: 10px;
  }
.el-input {
    width: 390px;
  }
</style>
